package com.ruoyi.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.equipment.EquipmentBasic;
import com.ruoyi.system.domain.equipment.EquipmentCheckPlan;
import com.ruoyi.system.service.equipment.IEquipmentCheckPlanService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 设备检测计划Controller
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/equipment/plan")
public class EquipmentCheckPlanController extends BaseController
{
    @Autowired
    private IEquipmentCheckPlanService equipmentCheckPlanService;

    /**
     * 查询设备检测计划列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentCheckPlan equipmentCheckPlan)
    {
        startPage();
        List<EquipmentCheckPlan> list = equipmentCheckPlanService.selectEquipmentCheckPlanList(equipmentCheckPlan);
        return getDataTable(list);
    }

    /**
     * 导出设备检测计划列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:export')")
    @Log(title = "设备检测计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentCheckPlan equipmentCheckPlan)
    {
        List<EquipmentCheckPlan> list = equipmentCheckPlanService.selectEquipmentCheckPlanList(equipmentCheckPlan);
        ExcelUtil<EquipmentCheckPlan> util = new ExcelUtil<EquipmentCheckPlan>(EquipmentCheckPlan.class);
        util.exportExcel(response, list, "设备检测计划数据");
    }

    /**
     * 获取设备检测计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentCheckPlanService.selectEquipmentCheckPlanById(id));
    }

    /**
     * 新增设备检测计划
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:add')")
    @Log(title = "设备检测计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentCheckPlan equipmentCheckPlan)
    {
        return toAjax(equipmentCheckPlanService.insertEquipmentCheckPlan(equipmentCheckPlan));
    }

    /**
     * 修改设备检测计划
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:edit')")
    @Log(title = "设备检测计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentCheckPlan equipmentCheckPlan)
    {
        return toAjax(equipmentCheckPlanService.updateEquipmentCheckPlan(equipmentCheckPlan));
    }

    /**
     * 删除设备检测计划
     */
    @PreAuthorize("@ss.hasPermi('equipment:plan:remove')")
    @Log(title = "设备检测计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentCheckPlanService.deleteEquipmentCheckPlanByIds(ids));
    }


    @Log(title = "导入设备检测计划", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('equipment:plan:export')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, HttpServletRequest request) throws Exception {
        ExcelUtil<EquipmentCheckPlan> util = new ExcelUtil<>(EquipmentCheckPlan.class);
        List<EquipmentCheckPlan> list = util.importExcel(file.getInputStream());

        String message = equipmentCheckPlanService.importHandler(list, getUsername());
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<EquipmentCheckPlan> util = new ExcelUtil<>(EquipmentCheckPlan.class);
        util.importTemplateExcel(response,"设备检测计划");
    }


    @GetMapping(value = "/remind")
    public AjaxResult remind()
    {
        equipmentCheckPlanService.checkPermitReportFile();
        return success();
    }
}
